package com.xej.seat.seating;

import java.util.Collections;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.xej.seat.tag.DefaultCustomerTag;
import com.xej.seat.tag.Tag;
import com.xej.seat.vo.Customer;
import com.xej.seat.vo.Hall;

/**
 * 权重排座
 * @author JiKe
 */
@Service
public class WeightSeating extends Seating {
	
	@Resource(type = DefaultCustomerTag.class)
	private Tag tag;
	
	@Override
	public void seating(Hall hall) throws Exception {
		//设值权重
		for(Customer cus : hall.getCustomers()) {
			double cweight = this.tag.getWeight(cus);
			cus.setCweight(cweight);
		}
		
		//默认排序
		Collections.sort(hall.getList());
		Collections.sort(hall.getCustomers());
		
		if(hall.getCustomers().size() > hall.getList().size()) {
			throw new IllegalArgumentException("座位不足！");
		}
		
		for(int i=0; i<hall.getList().size() && i<hall.getCustomers().size(); i++) {
			Customer customer = hall.getCustomers().get(i);
			hall.getList().get(i).setCusId(customer.getCusId());
			hall.getList().get(i).setName(customer.getCusName());
			hall.getList().get(i).setTitle(customer.getCusPosit());
			hall.getList().get(i).setOrg(customer.getInstName());
		}
	}
	
}
